package com.yxhl.zoume.domain.interactor.car.officialcar;

import com.google.protobuf.GeneratedMessageV3;
import com.yxhl.protobuf.MpvModelRequest;
import com.yxhl.protobuf.MpvModelResponse;
import com.yxhl.zoume.data.http.repository.car.OfficialCarRepository;
import com.yxhl.zoume.domain.DomainConstants;
import com.yxhl.zoume.domain.interactor.base.ProtoUseCase;

import javax.inject.Inject;
import javax.inject.Named;

import rx.Observable;
import rx.Scheduler;

/**
 * Created by sugarya on 16/8/26.
 */
public class QueryPriceAndDistanceUseCase extends ProtoUseCase<MpvModelResponse> {

    private OfficialCarRepository mOfficialCarRepository;


    @Inject
    public QueryPriceAndDistanceUseCase(@Named(DomainConstants.UI_THREAD) Scheduler uiThread,
                                        @Named(DomainConstants.EXECUTOR_THREAD) Scheduler executorThread,
                                        OfficialCarRepository officialCarRepository) {
        super(uiThread, executorThread);
        mOfficialCarRepository = officialCarRepository;
    }

    @Override
    protected Observable<MpvModelResponse> buildObservable(GeneratedMessageV3 message) {
        return mOfficialCarRepository
                .queryOfficialCarPriceAndDistance((MpvModelRequest) message)
                .subscribeOn(executorThread)
                .observeOn(uiThread);
    }
}
